var t = getApp(), a = 0, e = 0, i = "plugin.store-alone-temp.frontend.videoShare.video.get-list";

Page({
    data: {
        videoList: [],
        showLoading: !1,
        imgCount: 0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        bannerList: [],
        activitys1: [],
        activitys2: [],
        imagedata: {
            img_0: "../../../image/icon_index.png",
            img_1: "../../../image/icon_component.png",
            img_2: "../../../image/icon_commission.png",
            img_3: "../../../image/icon_cart.png",
            img_4: "../../../image/icon_I.png"
        },
        iPnoneBottomBol: !1,
        videoMore: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/video_more@2x.png",
        viderCancle: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/video_cancle@2x.png",
        btnStatus: !1,
        is_rotation: 0,
        is_show_cate: !1,
        cateList: [ {
            id: 0,
            name: "全部"
        } ],
        category_id: 0,
        swiperHeight: "",
        listData: [],
        taskID: "",
        taskDay: ""
    },
    onLoad: function(a) {
        this.getiPnoneBottom(), void 0 !== a.cat_id && null !== a.cat_id && this.setData({
            category_id: Number(a.cat_id)
        }), a.taskID && this.setData({
            taskID: a.taskID
        }), a.taskDay && this.setData({
            taskDay: a.taskDay
        }), 1 == t.globalData.store_alone_temp ? this.getData() : (this.getData(), this.getBanner(), 
        this.getBasicSet());
    },
    imageLoad: function(t) {
        var a = t.detail.width / t.detail.height;
        console.log(t.detail.width, t.detail.height);
        var e = 750 / a;
        e > this.data.swiperHeight && this.setData({
            swiperHeight: e
        });
    },
    bindchange: function(t) {
        this.setData({
            current: t.detail.current
        });
    },
    chooseSta: function() {
        this.setData({
            btnStatus: !this.data.btnStatus
        });
    },
    goluzhi: function() {
        wx.navigateTo({
            url: "/packageC/video_goods/releaseVideo/releaseVideo"
        });
    },
    onReady: function() {},
    gojilu: function(t) {
        wx.navigateTo({
            url: "/packageC/video_goods/myVideo/myVideo"
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    getBanner: function() {
        var a = this, e = t.getNetAddresss("plugin.video-share.frontend.set.getSlide");
        t._getNetWork({
            url: e,
            data: {},
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    bannerList: e.data.slide,
                    is_rotation: e.data.is_rotation
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onImageLoad: function(t) {
        var i = this, o = this.data.videoList;
        if (this.data.listData.push(t), this.data.imgCount += 1, this.data.imgCount == this.data.videoList.length) {
            var s = null, n = 0, d = 0, g = {};
            this.data.listData.sort(function(t, a) {
                return parseInt(a.currentTarget.id) - parseInt(t.currentTarget.id);
            }), this.data.listData.forEach(function(t, r) {
                n = t.detail.width, d = t.detail.height;
                for (var c = n / d, l = 0; l < o.length; l++) if (o[l].id == parseInt(t.currentTarget.id)) {
                    s = o[l];
                    break;
                }
                var u = i.data.activitys1, h = i.data.activitys2;
                a <= e ? (a += 176 / c + 60, u.push(s)) : (e += 176 / c + 60, h.push(s)), g = {
                    activitys1: u,
                    activitys2: h
                };
            }), this.setData(g), this.data.listData = [];
        }
    },
    changeCategory: function(t) {
        this.data.category_id = t.detail.name, this.data.imgCount = 0, this.getData();
    },
    getData: function() {
        var o = this;
        this.data.page = 1;
        var s = t.getNetAddresss(1 == t.globalData.store_alone_temp ? i : "plugin.video-share.frontend.video.getList");
        t._postNetWork({
            url: s,
            data: {
                page: 1,
                search: {
                    category_id: this.data.category_id
                }
            },
            success: function(t) {
                o.setData({
                    showLoading: !0
                });
                try {
                    var i = wx.getStorageSync("yz_basic_info").home.mailInfo.name || "";
                    wx.setNavigationBarTitle({
                        title: i
                    });
                } catch (t) {}
                var s = t.data;
                1 == s.result ? (o.setData({
                    isLoadMore: !0
                }), o.data.total_page = s.data.list.last_page, o.data.total_page || (o.data.total_page = 0), 
                o.setData({
                    videoList: []
                }), a = 0, e = 0, o.setData({
                    activitys1: [],
                    activitys2: [],
                    videoList: s.data.list.data
                })) : wx.showToast({
                    title: s.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getBasicSet: function() {
        var a = this, e = t.getNetAddresss("plugin.video-share.frontend.video.getBasicSet");
        t._getNetWork({
            url: e,
            data: {},
            success: function(t) {
                var e = t.data;
                1 == e.result && "1" == e.data.set.is_show_cate && a.getCategory();
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCategory: function() {
        var a = this, e = t.getNetAddresss("plugin.video-share.frontend.video.getCategory");
        t._getNetWork({
            url: e,
            data: {},
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    cateList: a.data.cateList.concat(e.data),
                    is_show_cate: !0
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toVideo: function(t) {
        var a = t.currentTarget.dataset.item, e = this.data.videoList.findIndex(function(t, e, i) {
            return t.id === a.id;
        });
        e = Math.ceil((e + 1) / 15), this.data.taskID ? wx.navigateTo({
            url: "/packageC/video_goods/VideoDetail/VideoDetail?vid=" + a.id + "&page=" + e + "&category=" + (this.data.category_id > 0) + "&taskID=" + this.data.taskID + "&taskDay=" + this.data.taskDay + "&task_type=video"
        }) : wx.navigateTo({
            url: "/packageC/video_goods/VideoDetail/VideoDetail?vid=" + a.id + "&page=" + e + "&category=" + (this.data.category_id > 0)
        });
    },
    gotoUpload: function() {
        wx.navigateTo({
            url: "/packageC/video_goods/videoAgreement/videoAgreement"
        });
    },
    getMoreData: function() {
        var a = this;
        if (a.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page = this.data.page + 1;
            var e = t.getNetAddresss(1 == t.globalData.store_alone_temp ? i : "plugin.video-share.frontend.video.getList");
            t._postNetWork({
                url: e,
                data: {
                    page: a.data.page,
                    search: {
                        category_id: this.data.category_id
                    }
                },
                success: function(t) {
                    var e = t.data;
                    if (a.data.isLoadMore = !0, 1 == e.result) {
                        var i = e.data.list.data;
                        a.setData({
                            videoList: a.data.videoList.concat(i)
                        });
                    } else a.data.page = a.data.page - 1, a.data.isLoadMore = !1;
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    goimgurl: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.url;
        console.log(a);
        try {
            wx.navigateTo({
                url: a
            });
        } catch (t) {
            wx.showToast({
                title: "链接设置错误",
                icon: "none",
                duration: 2e3
            });
        }
    },
    goindex: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    gocategory: function() {
        wx.reLaunch({
            url: "/packageG/pages/category_v2/category_v2"
        });
    },
    gocart: function() {
        wx.reLaunch({
            url: "/packageG/pages/buy/cart_v2/cart_v2"
        });
    },
    gomember: function() {
        wx.reLaunch({
            url: "/packageG/member_v2/member_v2"
        });
    }
});